<?php
/**
* This file is part of Webappkit, a packages system for PHP web apps
* @link http://webappkit.net
* @package webappkit
* @author J.Ducastel <nospam0@ducastel.name>
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*/
if (class_exists('waktool'))
	return;

/**
 * Generic tool builder for Kits
 * PHP5 version
 */
class WakTool implements iWakTool {

	public static function toolFactory($kit_id,$cfg=array()) {
		return new WakTool($kit_id,$cfg);
	}

	public function getKitId() {
		return $this->kit;
	}

	public function getCfg() {
		return $this->cfg;
	}
/*--------------------------------------------------------------------
CONSTRUCTOR
--------------------------------------------------------------------*/
	/**
	* "real" constructor.
	* will load conf
	* @access public
	* @param string $kit parent kit's id
	* @param string $cfg configuration data, will be merged with defaults
	*/
	protected function __construct($kit,$cfg=array()) {
		$this->kit=$kit;
		// getting defaults
		$class=get_class($this);
		$defaults=eval('return '.$class.'::$default_cfg;');
		// merging config with defaults
		if (is_array($cfg))
			$this->cfg=Webappkit::mergeArrays($defaults,$cfg);
		else
			$this->cfg=$defaults;
		// echo '<pre>default: '; print_r($defaults); echo '<br/> +'; print_r($cfg); echo '<br/> = '; print_r($this->cfg);
		// doing some more initialization
		$this->_init();
	}/**/
/*--------------------------------------------------------------------
VARS / MEMBERS
--------------------------------------------------------------------*/
	/**
	* @var string parent kit id
	*/
	protected $kit;

	/**
	* @var string self unique name within kit
	*/
	// var $name;

	/**
	 * @var array defaults for configuration data
	 */
	public static $default_cfg=array();

	/**
	 *@var array configuration data (defaults)
	 */
	protected $cfg=array();

	/**
	 * This method will be called by constructor,
	 * once configuration is imported.
	 * implement your post-config stuff there.
	 * @access protected
	 * @return bool
	 */
	protected function _init() {
		return true;
	}
}
